﻿using UnityEngine;
using System.Collections;
using CommonFactory;
using EnvironSystem;
using CharacterSystem;
using System;

/// <summary>
/// 角色孵化器基类
/// </summary>
public class CharacterSpawnBase : MonoBehaviour, ISpawn
{
    //MessageTerminal messageTerminal;
    protected CharacterFactoryBase factory;

    public string SpawnTag
    {
        get { return spawnTag; }
    }

    [SerializeField]
    protected string spawnTag = "";

    void Awake()
    {
        //messageTerminal = this.gameObject.AddComponent<MessageTerminal>();
        //messageTerminal.RegisterMessage("StartSpawn", OnMessage);
    }

    //public void OnMessage(IMessageArgs args)
    //{
    //    CreateItem();
    //}

    void OnDestroy()
    {

    }

    public virtual void OnCreated(CharacterBase character)
    {

    }

    public object Create()
    {
        CharacterBase character = factory.CreateProduct();
        character.transform.position = this.transform.position;
        EnvironmentSystemFacade.Inst.RegisterElement(1, character);
        OnCreated(character);
        return character;
    }
}
